<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no">
    <title>zepto入门</title>
    <link rel="shortcut icon" href="https://mat1.gtimg.com/chinanba/images/favicon.ico">
    <link rel="stylesheet" href="../css/index.css">
    <script src="../js/zepto.js"></script>
</head>
<body>
<ul class="menu">
    <li class="list"><a href="#">My Files1</a>
        <ul class="items">
            <li><a href="#">01&nbsp;Dropbox</a></li>
            <li><a href="#">02&nbsp;Dropbox</a></li>
            <li><a href="#">03&nbsp;Dropbox</a></li>
        </ul>
    </li>
    <li class="list"><a href="#">My Files2</a>
        <ul class="items">
           <li><a href="#">01&nbsp;Dropbox</a></li>
           <li><a href="#">02&nbsp;Dropbox</a></li>
           <li><a href="#">03&nbsp;Dropbox</a></li>
        </ul>
    </li>
    <li class="list"><a href="#">My Files3</a>
        <ul class="items">
            <li><a href="#">01&nbsp;Dropbox</a></li>
            <li><a href="#">02&nbsp;Dropbox</a></li>
            <li><a href="#">03&nbsp;Dropbox</a></li>
        </ul>
    </li>
    <li class="list"><a href="#">My Files4</a>
        <ul class="items">
            <li><a href="#">01&nbsp;Dropbox</a></li>
            <li><a href="#">02&nbsp;Dropbox</a></li>
            <li><a href="#">03&nbsp;Dropbox</a></li>
        </ul>
    </li>
</ul>
<script>
    let list = document.querySelectorAll('.list');
    function accordion(e) {
        e.stopPropagation();
        if (this.classList.contains('active')) {
            this.classList.remove('active');
        } else
        if (this.parentElement.parentElement.classList.contains('active')) {
            this.classList.add('active');
        } else {
            for (let i = 0; i < list.length; i++) {
                list[i].classList.remove('active');
            }
            this.classList.add('active');
        }
    }
    for (let i = 0; i < list.length; i++) {
        list[i].addEventListener('click', accordion);
    }
</script>
</body>
</html>